/*
*  Copyright 2019-2023 CY
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.ejweixin.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.ejweixin.domain.NgConstructionProgressUserLike;
import me.zhengjie.modules.ejweixin.service.NgConstructionProgressUserLikeService;
import me.zhengjie.modules.ejweixin.domain.vo.NgConstructionProgressUserLikeQueryCriteria;
import lombok.RequiredArgsConstructor;
import java.util.List;

import me.zhengjie.utils.SecurityUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import me.zhengjie.utils.PageResult;

/**
* @author cy
* @date 2025-05-26
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "工地进度点赞管理")
@RequestMapping("/api/ngConstructionProgressUserLike")
public class NgConstructionProgressUserLikeController {

    private final NgConstructionProgressUserLikeService ngConstructionProgressUserLikeService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('ngConstructionProgressUserLike:list')")
    public void exportNgConstructionProgressUserLike(HttpServletResponse response, NgConstructionProgressUserLikeQueryCriteria criteria) throws IOException {
        ngConstructionProgressUserLikeService.download(ngConstructionProgressUserLikeService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询工地进度点赞")
    @ApiOperation("查询工地进度点赞")
    @PreAuthorize("@el.check('ngConstructionProgressUserLike:list')")
    public ResponseEntity<PageResult<NgConstructionProgressUserLike>> queryNgConstructionProgressUserLike(NgConstructionProgressUserLikeQueryCriteria criteria, Page<Object> page){
        return new ResponseEntity<>(ngConstructionProgressUserLikeService.queryAll(criteria,page),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增工地进度点赞")
    @ApiOperation("新增工地进度点赞")
    public ResponseEntity<Object> createNgConstructionProgressUserLike(@Validated @RequestBody NgConstructionProgressUserLike resources){
        try {
            Long userId = SecurityUtils.getCurrentUserId();
            resources.setUserId(userId.intValue());
        }catch (BadRequestException e){
            System.out.println("未找到登陆的用户信息");
        }
        ngConstructionProgressUserLikeService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改工地进度点赞")
    @ApiOperation("修改工地进度点赞")
    @PreAuthorize("@el.check('ngConstructionProgressUserLike:edit')")
    public ResponseEntity<Object> updateNgConstructionProgressUserLike(@Validated @RequestBody NgConstructionProgressUserLike resources){
        ngConstructionProgressUserLikeService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除工地进度点赞")
    @ApiOperation("删除工地进度点赞")
    @PreAuthorize("@el.check('ngConstructionProgressUserLike:del')")
    public ResponseEntity<Object> deleteNgConstructionProgressUserLike(@RequestBody List<Integer> ids) {
        try {
            Long userId = SecurityUtils.getCurrentUserId();
            ngConstructionProgressUserLikeService.deleteAll(ids, userId.intValue());
        }catch (BadRequestException e){
            System.out.println("未找到登陆的用户信息");
        }
        return new ResponseEntity<>(HttpStatus.OK);
    }
}